import 'package:cached_network_image/cached_network_image.dart';
import 'package:casdon/app/config/theme/theme_extention.dart';
import 'package:casdon/modules/recipe/data/model/recipe_module_content_model.dart';
import 'package:casdon/modules/recipe/data/model/recipe_placeholder_data.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class RecipePromotionItem extends StatelessWidget {
  final RecipeModuleContentModel item;
  final VoidCallback? onTap;

  const RecipePromotionItem({super.key, required this.item, this.onTap});

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      behavior: HitTestBehavior.opaque,
      onTap: onTap,
      child: Container(
        width: double.infinity,
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(12.r),
        ),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            // 图片部分
            ClipRRect(
              borderRadius: BorderRadius.circular(8.r),
              child: CachedNetworkImage(
                imageUrl: item.imgUrl,
                width: double.infinity,
                height: 90.h, // 图片高度可固定
                fit: BoxFit.cover,
                fadeInDuration: Duration.zero,
                placeholder: (context, url) =>
                    Container(color: Colors.grey.shade200),
                errorWidget: (context, url, error) {
                  return Image.network(
                    recipePlaceHolderImgUrl,
                    fit: BoxFit.cover,
                    width: double.infinity,
                    height: 90.h,
                    errorBuilder: (context, error, stackTrace) {
                      return Container(
                        color: Colors.grey[200],
                        child: const Icon(Icons.image_outlined, color: Colors.grey),
                      );
                    },
                  );
                },
              ),
            ),
            SizedBox(height: 8.h),

            // 标题部分
            Padding(
              padding: EdgeInsets.symmetric(horizontal: 12.w),
              child: Text(
                item.title,
                style: context.theme.textTheme.bodyMedium?.copyWith(
                  color: context.customColorThemeNonNull.textColor1,
                  fontWeight: FontWeight.w500,
                ),
                maxLines: 2,
                overflow: TextOverflow.ellipsis,
              ),
            ),

            SizedBox(height: 8.h),
          ],
        ),
      ),
    );
  }
}
